<?php
class ControllerModuleAlsoBuy extends Controller {
	protected function index($setting) {
		static $module = 0;
		$this->data['module'] = 'AB' . $module++;
		
		$product_id = G('product_id', 0);
		
		if (!($product_id && ROUTE == 'product/product')) return;
		
		M('catalog/product');		
		$results = $this->model_catalog_product->getAlsoBuyProducts($product_id, $setting['limit']);
		
		if (!$results) return;
		
		$this->language->load('module/alsobuy');
		
		$this->data['products'] = array();
		
		foreach ($results as $result) {

			$this->data['products'][] = array(
				'product_id' => $result['product_id'],
				'thumb'   	 => thumb($result['image'], $setting['image_width'], $setting['image_height']),
				'name'    	 => $result['name'],
				'summary'    => $result['summary'],
				'price'       => pprintf($result['price'], $result['tax_class_id']),
				'special'     => pprintf($result['special'], $result['tax_class_id']),
				'rating'     => C('config_review_status') ? $result['rating'] : false,
				'reviews'    => sprintf($this->_['text_reviews'], (int)$result['reviews']),
				'href'    	 => $result['link'],
			);
		}
		$this->data['heading_title'] = $this->_['heading_title'];
		$this->render('module/' . (!empty($setting['template']) ? $setting['template'] : 'alsobuy.tpl'));
	}
}
?>